package org.example.hansp.collection_.map_.exercise;

import java.util.*;

@SuppressWarnings({"all"})
public class MapExercise01 {
    public static void main(String[] args) {
        Map map = new HashMap();
        map.put("001",new Employee(001,"liam",20000.00));
        map.put("002",new Employee(002,"elias",15000.00));
        map.put("003",new Employee(003,"frank",25000.00));
        Set set=map.keySet();
        for (Object key : set) {
            Employee employee=(Employee)map.get(key);
            if(employee.getSalary()>18000){
                System.out.println(employee.getId()+" "+employee.getName()+" "+employee.getSalary());
            }

        }
        Iterator itr=set.iterator();
        while (itr.hasNext()) {
            String key=(String)itr.next();
            Employee employee=(Employee)map.get(key);
            System.out.println(employee.getId()+" "+employee.getName()+" "+employee.getSalary());
        }
        Set set1 = map.entrySet();
        for (Object key : set1) {//从set集合中取出一个个Node结点
            //把它转换为Entry，Entry里面有getKey()和getValue()方法
            Map.Entry entry=(Map.Entry)key;
            System.out.println(entry.getClass());//Node
            Employee employee=(Employee)entry.getValue();
            System.out.println(employee.getId()+" "+employee.getName()+" "+employee.getSalary());
        }
        /*先把employee对象和key包裹到Node，再把Node形成一个Entry放到集合Set中，entryset的数据类型为Entry
        * */

    }
}
class Employee{
    private int id;
    private String name;

    private double salary;

    public Employee( int id,String name,  double salary) {
        this.name = name;
this.id=id;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Employee)) return false;
        Employee employee = (Employee) o;
        return id == employee.id && Double.compare(salary, employee.salary) == 0 && Objects.equals(name, employee.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, name, salary);
    }
}
